﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace DotNet.Utilities
{
    public static class MyRegex
    {
        /// <summary>
        /// 得到字符串里面匹配的正则表达式集合
        /// </summary>
        /// <param name="str">扩展的字符串</param>
        /// <param name="strRegex">正则表达式</param>
        /// <returns></returns>
        public static List<string> GetRegexStringCollection(this string str ,string strRegex)
        {
            MatchCollection matchText = Regex.Matches(str, strRegex, RegexOptions.IgnoreCase);//得到匹配项的集合
            List<string> strList = new List<string>();

            foreach (Match matchSingleStr in matchText)
            {
                strList.Add(matchSingleStr.Value);
            }
            return strList;
        }
        /// <summary>
        /// 替换正则表达式的字符串
        /// </summary>
        /// <param name="str">源字符串</param>
        /// <param name="strRegex"></param>
        /// <param name="replaceStr"></param>
        /// <returns></returns>
        public static string RegexReplace(this  string str,string strRegex,string replaceStr)
        {
           return Regex.Replace(str, strRegex, replaceStr, RegexOptions.IgnoreCase);
        }
    }
}
